package com.cn.api.error;

import com.cn.api.resource.BaseResultVo;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class SpringErrorHandler {
	@ExceptionHandler({ Exception.class })
	@ResponseStatus(value = HttpStatus.NOT_FOUND)
	@ResponseBody
	public BaseResultVo<String> notFound(Exception ex) {
		ex.printStackTrace();
		return new BaseResultVo<String>(500, ex.getMessage());
	}

	@ResponseStatus(HttpStatus.OK)
	@ResponseBody
	@ExceptionHandler(ExceptionExpand.class)
	public BaseResultVo<String> signException(ExceptionExpand ex) {
		return new BaseResultVo<String>(ex.getCode(), ex.getMessage());
	}

}
